import { nextTick, ref } from 'vue';
import { Input, message } from 'ant-design-vue';
import dayjs from 'dayjs';
import { downLoadExcel, post } from '@/service/api/api';

const searchParam = ref({
  moduleNo: null,
  remark: null
});

const pageRef = ref(null);

function updateStackup(row, pageFn) {
  post('/qms/agv/DrillDailyAlum/update', row).then(({ data, error }) => {
    if (!error) {
      message.success('修改成功');
      pageFn.resetGetData();
    }
  });
}

export default {
  showTableToolsBtn: false,
  url: '/qms/agv/DrillDailyAlum/list',
  getPageRef(mainPageRef) {
    pageRef.value = mainPageRef;
  },
  canRowDblclick: false,
  searchFormList: [
    {
      type: 'input',
      key: 'moduleNo',
      label: '机台号',
      placeholder: '请输入机台号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'input',
      key: 'serialNum',
      label: '单据号',
      placeholder: '请输入单据号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'input',
      key: 'remark',
      label: '长宽',
      placeholder: '请输入长宽',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    }
  ],
  searchParam,
  column: [
    {
      key: 'dataIndex',
      dataIndex: 'dataIndex',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'moduleNo',
      dataIndex: 'moduleNo',
      title: '生产型号',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'serialNum',
      dataIndex: 'serialNum',
      title: '单据号',
      width: 130,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'drillPnlQty',
      dataIndex: 'drillPnlQty',
      title: '投料Pnl数',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'meridional',
      dataIndex: 'meridional',
      title: '尺寸长',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'zonal',
      dataIndex: 'zonal',
      title: '尺寸宽',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'thickness',
      dataIndex: 'thickness',
      title: '板厚',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'stackup',
      dataIndex: 'stackup',
      title: '叠层',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true,
      customRender: ({ record }) => {
        return (
          <Input
            value={record.stackup}
            class="min-form-control"
            onChange={e => {
              const val = e.target.value;
              record.stackup = val;
              nextTick(() => {
                const pageFn = {
                  ...pageRef.value.value,
                  stackup: val
                };
                updateStackup(record, pageFn);
              });
            }}
          ></Input>
        );
      }
    },

    {
      key: 'axesNumber',
      dataIndex: 'axesNumber',
      title: '轴数',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'shimNumber',
      dataIndex: 'shimNumber',
      title: '垫片数量',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'alumNumber',
      dataIndex: 'alumNumber',
      title: '普通铝片数量',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'minHoleDiameter',
      dataIndex: 'minHoleDiameter',
      title: '最小孔径',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'coverAlumNumber',
      dataIndex: 'coverAlumNumber',
      title: '覆膜铝片数量',
      width: 140,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'remark',
      dataIndex: 'remark',
      title: '备注',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'createTime',
      dataIndex: 'createTime',
      title: '创建时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateTime',
      dataIndex: 'updateTime',
      title: '修改时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateBy',
      dataIndex: 'updateBy',
      title: '修改人',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    }
  ],
  scroll: { x: 'auto', y: 'auto' },
  otherBtnList: [
    {
      icon: 'icon-ic-round-download ',
      name: '导出',
      iconType: 3,
      auth: 'grinding-machine:download',
      handleClick: () => {
        downLoadExcel(
          `/qms/agv/Exporter/exportExcel`,
          {
            formId: 92
          },
          `研磨机汇总导出${dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`
        );
      }
    }
  ],
  otherBtnList: [
    {
      icon: 'icon-ic-round-download ',
      name: '当天汇总数据导出',
      iconType: 3,
      auth: 'aluminum-plate-used:today-download',
      handleClick: () => {
        downLoadExcel(
          `/qms/agv/DrillDailyAlum/export`,
          {
            ...searchParam.value
          },
          `铝片使用量当天汇总数据导出${dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`
        );
      }
    },
    {
      icon: 'icon-ic-round-download ',
      name: '每日汇总数据导出',
      iconType: 3,
      auth: 'aluminum-plate-used:everyday-download',
      handleClick: () => {
        downLoadExcel(
          `/qms/agv/Exporter/exportExcel`,
          {
            formId: 117,
            ...searchParam.value
          },
          `每日铝片使用量统计${dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`
        );
      }
    }
  ]
};
